package com.odobenus.controller;

import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.odobenus.common.JsonObjectBase;
import com.odobenus.common.JsonObjectUtils;
import com.odobenus.common.JsonSimpleObject;


/**
 * @author liaoqiqi
 * @version 2013-11-26
 */
public class BaseController implements ApplicationContextAware {

    protected ApplicationContext context;

    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
        this.context = arg0;
    }

    /**
     * OK：非列表数据
     *
     * @param key
     * @param value
     *
     * @return
     */
    protected <T> JsonObjectBase buildSuccess(String key, T value) {
        return JsonObjectUtils.buildObjectSuccess(key, value);
    }
    /**
     * OK: 列表数据
     *
     * @param value
     * @param totalCount
     * @param <T>
     *
     * @return
     */
    protected <T> JsonObjectBase buildListSuccess(List<?> value, int totalCount) {

        return JsonObjectUtils.buildListSuccess(value, totalCount, null);
    }
    /**
     * OK：非列表数据
     *
     * @param value
     *
     * @return
     */
    protected <T> JsonSimpleObject buildSuccess(T value) {
        return JsonObjectUtils.buildSimpleObjectSuccess(value);
    }
}
